package com.example.rbac.controller.restful;


import com.example.rbac.entity.Menu;
import com.example.rbac.entity.Page;
import com.example.rbac.entity.User;
import com.example.rbac.entity.defefult.Result;
import com.example.rbac.mapper.cache.RedisDao;
import com.example.rbac.service.UserService;
import com.example.rbac.service.cache.UserCacheService;
import com.example.rbac.uitls.ResultUtil;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by Administrator on 2017/10/12.
 */

@RestController
@RequestMapping("/api/User")
public class UserRestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private UserService userService;

    @Autowired
    private UserCacheService userCacheService;


    @GetMapping("getList")
    public Result<User> getList() {
        return ResultUtil.success(userService.findList());
    }

    @PostMapping("/memberStop")
    public Result memberStop(User user) {
        user.setState("0");
        Integer result = userService.updateStateById(user);
        return ResultUtil.success(result);
    }

    @PostMapping("/memberStart")
    public Result memberStart(User user) {
        user.setState("1");
        Integer result = userService.updateStateById(user);
        return ResultUtil.success(result);
    }


    @GetMapping("/page")
    public Page getPager(Integer pageNum, Integer pageSize) {
        Page<User> users = new Page<User>();
        if (pageNum == null || pageSize == null) {
            pageNum = 1;
            pageSize = 2;
        }
        users = userService.getPager(pageNum, pageSize);
        return users;
    }
}
